<template>
  <div class="g-bd" id="m-disc-pl-c">

    <div class="g-wrap p-pl f-pr">
      <div class="u-title f-cb">
        <h3>
          <span class="f-ff2 d-flag">申请成为音乐人</span>
        </h3>
      </div>

      <div class="artist-step-wrap">
        <artist-apply-steps :active="active"></artist-apply-steps>
      </div>

      <div class="read-agreement" v-if="active === 0">
        <read-agreement>
        </read-agreement>
        <div style="margin-left: auto; margin-right: auto; width: 100px">
          <el-button type="primary" @click="active = 1">同  意</el-button>
        </div>
      </div>

      <div class="edit-playlist"  v-if="active === 1">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="歌手名" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
          </el-form-item>
          <el-form-item label="歌手介绍" prop="description">
            <el-input type="textarea" v-model="ruleForm.description"></el-input>
          </el-form-item>
          <el-form-item label="上传歌手封面">
            <el-upload
              v-loading="loading"
              class="avatar-uploader"
              :action="uploadServiceUrl"
              :show-file-list="false"
              :on-progress="handleProgress"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload">
              <img v-if="imageUrl" :src="changeUrlToResizeImg(imageUrl, 178)" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
            <!--<el-button @click="back()">取消</el-button>-->
          </el-form-item>
        </el-form>
      </div>

      <div class="wait-verify" v-if="active === 2">
        <el-alert
          title="申请成功"
          type="success"
          description="请等待审核结果"
          show-icon>
        </el-alert>
      </div>
    </div>
  </div>
  <!--<div>-->
    <!--<artist-apply-steps :active="active"></artist-apply-steps>-->
  <!--</div>-->
</template>

<script>
  import {userCreatedPlaylists, userSubscribePlaylists, apiContext} from "../service/getData"
  import {getUser} from '../util/userUtils'
  import ArtistApplySteps from '../components/artist-apply-steps'
  import ReadAgreement from '../components/readAgreement'

  export default {
    name: 'artistApply',
    components: {ReadAgreement, ArtistApplySteps},
    data() {
      return {
        active: 0,
        loading: false,
        user: {},
        uploadServiceUrl: "",
        imageUrl: '',
        imageId: '',
        alertMessage: '',
        ruleForm: {
          description: "",
        },
        rules: {
          name: [
            { required: true, message: "请填写歌手名", trigger: 'blur' }
          ],
          description: [
            { required: false, message: '请填写歌手介绍', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      changeUrlToResizeImg(picUrl, size) {
        return picUrl.replace(/yunmusic_dev/, "resize_" + size + 'x' + size);
      },
      back() {
        this.isEdit = false;
      },
      submitForm() {
        this.$http.post(apiContext+"artistReview/add", {
          userid: this.user.id,
          name: this.ruleForm.name,
          description: this.ruleForm.description,
          picUrlId: this.imageId
        }, {
          emulateJSON : true,
          headers: {
            'Content-Type': 'x-www-form-urlencoded',
            'userId': this.user.id,
            'userToken': this.user.userToken
          }}).then(res => {
          console.log(res);
          let status = res.body.status;
          if (status === 200) {
            this.$message({
              message: "提交审核成功",
              type: 'success'
            });
            this.active = 2;
            // 刷新用户创建的歌单
            // this.getCreatedPlaylists();
          } else {
            this.$message({
              message: res.body.msg,
              type: 'error'
            });
          }
        })
      },
      handleProgress(event, file, fileList) {
        this.loading = true;
      },
      handleAvatarSuccess(res, file) {
        console.log(res);
        this.loading = false;
        if (res.status === 200) {
          // this.imageUrl = URL.createObjectURL(file.raw);
          this.$message.success("上传成功");
          let data = res.data;
          this.imageUrl = data.filePath;
          this.imageId = data.fileId;
        } else {
          this.$message.error(res.msg);
        }

      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
    },
    mounted () {
      this.uploadServiceUrl = apiContext + "upload/cover/artist"
      this.user = getUser()
      console.log(this.user)
    }
  }
</script>

<style scoped>
  .g-bd, .g-bd1, .g-bd2, .g-bd3, .g-bd4, .g-bd5, .g-bd6, .g-bd7 {
    width: 980px;
    min-height: 700px;
    _height: 700px;
    /*margin: 0 auto;*/
    background-color: #fff;
    border: 1px solid #d3d3d3;
    border-width: 0 1px;
  }

  .g-wrap {
    padding: 40px;
  }

  .f-pr {
    position: relative;
    zoom: 1;
  }

  /*div {*/
    /*display: block;*/
  /*}*/

  .u-title {
    height: 40px;
    border-bottom: 2px solid #c20c0c;
  }

  .f-cb {
  }

  .u-title h3 {
    float: left;
    font-size: 24px;
    font-weight: normal;
  }

  .f-ff2 {
    font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  }

  .u-title .menu {
    _position: absolute;
    font-size: 12px;
    font-weight: normal;
    margin: 2px 0 0 12px;
  }

  .u-btn2, .u-btn2:hover {
    text-decoration: none;
  }

  .u-btn2 {
    padding: 0 5px 0 0;
    white-space: nowrap;
  }

  .u-btn2, .u-btn2 i, .u-btn2 .icn, .u-btni, .u-btni i, .u-tag, .u-tag i, .u-btni-addply .ply {
    background: url(../image/button2.png) no-repeat 0 9999px;
  }

  .u-btn2-1 {
    color: #333;
    background-position: right -100px;
  }

  .u-title .menu i {
    color: #0c73c2 !important;
    padding: 0 10px 0 15px;
    _padding-right: 20px;
  }

  .u-btn2-1 i {
    color: #333;
    background-position: 0 -59px;
  }

  .u-btn2 i {
    padding: 0 15px 0 20px;
    pointer-events: none;
  }

  .u-btn2, .u-btn2 i {
    display: inline-block;
    height: 31px;
    line-height: 31px;
    overflow: hidden;
    vertical-align: top;
    text-align: center;
    cursor: pointer;
  }

  .u-icn, .u-icn2, .u-icn3 {
    display: inline-block;
    overflow: hidden;
    vertical-align: middle;
  }

  .u-icn, .u-title-1 .out .icon {
    background: url(../image/icon.png) no-repeat 0 9999px;
  }

  .u-title .menu .u-icn-38 {
    margin-left: 5px;
    _position: absolute;
    _top: 13px;
  }

  .u-icn-38 {
    width: 8px;
    height: 5px;
    background-position: -70px -543px;
  }

  .u-btn {
    display: inline-block;
  }

  /*.u-btn, div.u-page a, div.u-page a.js-selected, div.u-page a.znxt.js-disabled, div.u-page a.zprv.js-disabled {*/
  /*background: url(../image/button.png) no-repeat 0 9999px;*/
  /*}*/

  .f-fr {
    float: right;
  }

  .u-title .u-btn-hot .a1, .u-title .u-btn-time .a1, .u-title .u-btn-new .a2, .u-title .u-btn-area .a2, .u-title .u-btn-song .a1 {
    color: #fff;
  }

  .u-title .u-btn .a1, .u-title .u-btn .a2 {
    float: left;
    width: 46px;
    height: 29px;
    line-height: 29px;
    text-align: center;
  }

  .f-cb:after {
    clear: both;
    content: '.';
    display: block;
    height: 0;
    visibility: hidden;
  }

  .p-pl .m-cvrlst {
    margin: 30px 0 0 -50px;
  }

  .m-cvrlst li {
    float: left;
    display: inline-block;
    width: 140px;
    height: 188px;
    overflow: hidden;
    padding: 0 0 30px 50px;
    line-height: 1.4;
  }

  .u-cover-1 {
    width: 140px;
    height: 140px;
  }

  .u-cover {
    position: relative;
    display: block;
  }

  .u-cover img {
    display: block;
    width: 100%;
    height: 100%;
  }

  img, .txt {
    border: 0;
  }

  .u-cover-1 .msk {
    background-position: 0 0;
  }

  .u-cover .msk {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .u-cover .bottom, .u-cover .msk, .n-musicsd .lst .avatar .msk {
    background: url(../image/coverall.png) no-repeat;
  }

  .u-cover .bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 27px;
    background-position: 0 -537px;
    color: #ccc;
  }

  .u-cover .icon-play:hover {
    background-position: 0 -60px;
  }

  .u-cover .icon-play {
    position: absolute;
    right: 10px;
    bottom: 5px;
    width: 16px;
    height: 17px;
    background-position: 0 0;
  }

  .u-cover .icon-headset, .u-cover .icon-play {
    display: inline-block;
  }

  .u-cover .ply, .u-cover .icon-headset, .u-cover .icon-play, .u-face .msk, .n-note .head .msk, .icn-vip, .icn-daren, .u-checkbox {
    background: url(../image/iconall.png) no-repeat;
  }

  .u-cover .icon-headset {
    float: left;
    width: 14px;
    height: 11px;
    background-position: 0 -24px;
    margin: 9px 5px 9px 10px;
  }

  .u-cover .nb {
    float: left;
    margin: 7px 0 0 0;
  }

  .m-cvrlst li .dec {
    margin: 8px 0 3px;
    font-size: 14px;
  }

  .m-cvrlst li p {
    width: 100%;
  }

  .m-cvrlst li .tit {
    display: inline-block;
    max-width: 100%;
    _width: 100%;
    vertical-align: middle;
  }

  .s-fc0, a.s-fc0:hover {
    color: #000;
  }

  .f-thide {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
  }

  .s-fc4, a.s-fc4:hover {
    color: #999;
  }

  .m-cvrlst li .nm {
    display: inline-block;
    max-width: 85%;
    vertical-align: middle;
  }

  .m-cvrlst li .nm-icn {
    max-width: 76%;
  }

  .s-fc3, a.s-fc3:hover {
    color: #666;
  }

  .f-thide {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
  }

  .m-cvrlst li p .u-icn {
    margin-top: -1px;
    _margin-top: -3px;
  }

  .u-icn-84 {
    width: 12px;
    height: 13px;
    background-position: -65px -840px;
  }

  .u-icn, .u-icn2, .u-icn3 {
    display: inline-block;
    overflow: hidden;
    vertical-align: middle;
  }

  div.u-page {
    margin: 20px 0;
    text-align: center;
  }

  /*.u-btn, div.u-page a, div.u-page a.js-selected, div.u-page a.znxt.js-disabled, div.u-page a.zprv.js-disabled {*/
  /*background: url(../image/button.png) no-repeat 0 9999px;*/
  /*}*/

  div.u-page .zbtn {
    width: 69px;
    height: 24px;
    line-height: 24px;
    color: #333;
    text-align: left;
    padding: 0;
  }

  div.u-page .zbtn, div.u-page .zpgi {
    margin: 0 1px 0 2px;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 2px;
    vertical-align: middle;
  }

  .u-btn, div.u-page a, div.u-page a.js-selected, div.u-page a.znxt.js-disabled, div.u-page a.zprv.js-disabled {
    background: url(../image/button.png) no-repeat 0 9999px;
  }

  .u-btn-hot {
    width: 93px;
    height: 29px;
    background-position: 0 0;
  }

  .u-btn-time {
    width: 93px;
    height: 29px;
    background-position: 0 -32px;
  }

  div.u-page .zpgi {
    height: 22px;
    padding: 0 8px;
    background-color: #fff;
    line-height: 22px;
  }

  div.u-page .zpgi:hover {
    border-color: #666;
  }

  div.u-page a:hover {
    text-decoration: none;
  }

  div.u-page a.zprv.js-disabled, div.u-page a.zprv.js-disabled:hover {
    background-position: 0 -620px;
    color: #cacaca;
    cursor: default;
  }

  div.u-page a.js-selected, div.u-page a.js-selected:hover {
    background-position: 0 -650px;
    border-color: #A2161B;
    color: #fff;
    cursor: default;
  }

  div.u-page .zbtn, div.u-page .zpgi {
    margin: 0 1px 0 2px;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 2px;
    vertical-align: middle;
  }

  div.u-page .zbtn {
    width: 69px;
    height: 24px;
    line-height: 24px;
    color: #333;
    text-align: left;
    padding: 0;
  }

  div.u-page .zprv {
    width: 47px;
    padding-left: 22px;
    background-position: 0 -560px;
  }

  div.u-page .znxt {
    width: 57px;
    padding-left: 12px;
    background-position: -75px -560px;
  }

  .tag-cascader {
    width: 100px;
  }

  .tag-cascader-warp {
    /*margin-bottom: 20px;*/

  }

  .edit-playlist {
    margin-top: 30px;
    margin-left: auto;
    margin-right: auto;
    width: 700px;
  }

  .avatar-uploader {
    width: 178px;
    height: 178px;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .artist-step-wrap {
    margin-top: 5px;
    margin-left: auto;
    margin-right: auto;
    width: 700px;
  }

  .artist-step {

  }

  .read-agreement {
    padding: 15px;
  }

  .wait-verify {
    margin-top: 20px;
    width: 500px;
    margin-left: auto;
    margin-right: auto;
  }

</style>
